﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Site.Master" AutoEventWireup="true" CodeBehind="EditExperiment.aspx.cs" Inherits="BEELab.EditExperiment" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Experiment Design</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server">
    <div id="wrap" class="clearfix">
        
        <asp:Label ID="lblEdit" runat="server" Visible="true">
            <a id="btnBack" runat="server" class="back-btn" href="ExperimentManagement.aspx">Back</a>
            <h2 class="headline">Experiment Design</h2>
        </asp:Label>
        <div class="sign-form">
            <h3>Experiment Information</h3>
            <div class="input-hold">
                <asp:Label ID="Label1" CssClass="sign-label" AssociatedControlID="txtName" runat="server">Name</asp:Label>
                <asp:TextBox CssClass="sign-input" ID="txtName" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvtxtName" CssClass="field-validation-error" ControlToValidate="txtName" ValidationGroup="AddExperimentGroup" runat="server" ErrorMessage="* Name is required." Text="*"></asp:RequiredFieldValidator>
            </div>
            <div class="input-hold">
                <asp:Label ID="Label2" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                <asp:TextBox CssClass="text-area" ID="txtDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvtxtDescription" Display="Dynamic" ControlToValidate="txtDescription" ValidationGroup="AddExperimentGroup" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
            </div>

            <div class="input-hold">
                <asp:Button CssClass="sign-submit" ValidationGroup="AddExperimentGroup" runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" />
            </div>
            
        </div>
        <div class="error">
            <asp:ValidationSummary runat="server" ID="vsNewExperiment" ValidationGroup="AddExperimentGroup" CssClass="field-validation-error" />
            <p>&nbsp;</p>
        </div>

        <div class="clr"></div>
        <div class="dashboard-hold">
            <div class="block">
                <asp:Label ID="lblUpdateMessage" runat="server" Visible="false" ForeColor="Red"></asp:Label>
                <h3>Stage List</h3>
                <a href="#new-experimentstage" class="abbtn fancybox">New Stage</a>

                <div id="new-experimentstage" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none">
                    
                    <asp:Label ID="lblNew" runat="server" Visible="true">
                    <h2 class="headline">New Experiment Stage</h2>
                    </asp:Label>

                    <div class="sign-form">
                        <div class="input-hold">
                            <asp:Label ID="Label4" CssClass="sign-label" AssociatedControlID="TextBox1" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="StageGroup" ControlToValidate="TextBox1" ForeColor="Red" Text="*" runat="server" Display="Dynamic" ErrorMessage="* Name is required"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="StageRegularExpressionValidator" ForeColor="Red" ValidationGroup="StageGroup" ControlToValidate="TextBox1" runat="server" ErrorMessage="* Name already in use"></asp:RegularExpressionValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label5" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                            <asp:TextBox ID="TextBox2" CssClass="text-area" runat="server" TextMode="MultiLine"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="StageGroup" ForeColor="Red" Text="*" ControlToValidate="txtDescription" runat="server" ErrorMessage="* Description is required."></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ValidationGroup="StageGroup" ID="Button1" Text="Submit" runat="server" OnClick="Button1_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary ID="vsStage" runat="server" ValidationGroup="StageGroup" />
                        <p>&nbsp</p>
                    </div>

                </div>
                <asp:GridView ID="gvStage" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" CssClass="dash-col" DataSourceID="SqlDataSource1" OnRowDeleting="gvStage_RowDeleting">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:BoundField DataField="ProgramID" HeaderText="ProgramID" SortExpression="ProgramID" Visible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditStage.aspx?ID={0}" Text="Edit" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="DuplicateStage.aspx?ID={0}" Text="Duplicate" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="MoveStage.aspx?ID={0}" Text="Move" />
                        <asp:CommandField ShowDeleteButton="True" ShowHeader="True" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM Variables WHERE ID IN (SELECT ElementID FROM ContainerElements WHERE Type='Variable' AND ContainerID IN (SELECT ID FROM Containers WHERE StageID=@ID)); DELETE FROM Stages WHERE ID=@ID" SelectCommand="SELECT * FROM [Stages] WHERE ([ProgramID] = @ProgramID)">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="gvStage" Name="ID" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:QueryStringParameter Name="ProgramID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>

        <div class="dashboard-hold">
            <div class="block">
                <h3>Set First Stage</h3>
                <div class="sign-form">
                    <div class="input-hold">
                        <asp:Label ID="Label10" CssClass="sign-label" AssociatedControlID="ddlStage" runat="server">First Stage</asp:Label>
                        
                        <asp:DropDownList CssClass="sign-select" ID="ddlStage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlStage_SelectedIndexChanged" DataSourceID="SqlDataSource4" DataTextField="Name" DataValueField="Name">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource4" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT [Name] FROM [Stages] WHERE ([ProgramID] = @ProgramID)" runat="server">
                            <SelectParameters>
                                <asp:QueryStringParameter Name="ProgramID" QueryStringField="ID" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </div>

                    <div class="input-hold">
                        <asp:Button CssClass="sign-submit" ID="Button4" Text="Set" runat="server" OnClick="Button4_Click" />
                    </div>
                </div>
            </div>
        </div>
        
        <div class="spacer"></div>

        <div class="dashboard-hold">
            <div class="block">
                <h3>Variable List</h3>

                <a href="#new-experimentvariable" id="newVariable" class="abbtn fancybox">New Variable</a>
                <div id="new-experimentvariable" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none">
                    
                    <h2 class="headline" id="new-variable">New Variable</h2>

                    <div class="sign-form">

                        <div class="input-hold">
                            <asp:Label ID="Label3" CssClass="sign-label" AssociatedControlID="TextBox3" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="TextBox3" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name is required" Text="*"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ValidationExpression="[a-zA-Z][_a-zA-Z0-9]*" EnableClientScript="True" ID="RegexValidator1" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name must be a valid JS variable name"></asp:RegularExpressionValidator>
                            <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="RegexValidator2" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name already in use"></asp:RegularExpressionValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label6" CssClass="sign-label" AssociatedControlID="TextBox4" runat="server">Description</asp:Label>
                            <asp:TextBox CssClass="text-area" ID="TextBox4" runat="server" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox4" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label7" CssClass="sign-label1" AssociatedControlID="txtDefaultValue" runat="server">Default Value <br /><span>String values must be enclosed by double quotation marks</span></asp:Label>
                            <asp:TextBox ID="txtDefaultValue" CssClass="sign-input" runat="server"></asp:TextBox>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label8" CssClass="sign-label" AssociatedControlID="rblScope" runat="server">Scope</asp:Label>
                            <asp:RadioButtonList CssClass="sign-radio list-space" runat="server" ID="rblScope" RepeatDirection="Horizontal">
                                <asp:ListItem Text="Session" Value="Session"></asp:ListItem>
                                <asp:ListItem Text="Subject" Value="Subject"></asp:ListItem>
                            </asp:RadioButtonList>

                            <asp:RequiredFieldValidator ID="rfvddlScope" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="rblScope" runat="server" ErrorMessage="* Scope is required." InitialValue="Selecet Scope" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ID="Button2" Text="Submit" runat="server" ValidationGroup="VariableGroup" OnClick="Button2_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <p>&nbsp</p>
                    </div>

                </div>

                <asp:GridView ID="gvVariable" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" CssClass="dash-col" DataSourceID="SqlDataSource2">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:BoundField DataField="ProgramID" HeaderText="ProgramID" SortExpression="ProgramID" Visible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditVariable.aspx?ID={0}" Text="Edit" />
                        <asp:CommandField ShowDeleteButton="True" ShowHeader="True" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM Variables WHERE ID=@ID" SelectCommand="SELECT [ID], [ProgramID], [Name], [Description] FROM [Variables] WHERE ([ProgramID] = @ProgramID)">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="gvVariable" Name="ID" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:QueryStringParameter Name="ProgramID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>

        <div class="dashboard-hold">
            <div class="block">
                <h3>Session List</h3>
                <a href="#new-experimentsession" class="abbtn fancybox">New Session</a>
                <div id="new-experimentsession" style="width: 640px; padding: 24px; border: 1px solid #ddd; display:none">

                    <asp:Label ID="Label9" runat="server" Visible="true">
                    <h2 class="headline">New Session</h2>
                    </asp:Label>

                    <div class="sign-form">
                        <div class="input-hold">
                            <asp:Label ID="Label11" CssClass="sign-label" AssociatedControlID="txtName" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="TextBox5" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ValidationGroup="SessionGroup" ID="RequiredFieldValidator5" ForeColor="Red" Text="*" ControlToValidate="txtName" runat="server" ErrorMessage="* Name is required."></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">

                            <asp:Label ID="Label12" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                            <asp:TextBox CssClass="text-area" ID="TextBox6" runat="server" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ValidationGroup="SessionGroup" ID="RequiredFieldValidator6" ForeColor="Red" Text="*" ControlToValidate="txtDescription" runat="server" ErrorMessage="* Description is required."></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ID="Button3" Text="Submit" runat="server" ValidationGroup="SessionGroup" OnClick="Button3_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary ID="vsSession" runat="server" ValidationGroup="SessionGroup" />
                        <p>&nbsp</p>
                    </div>
                </div>

                <asp:GridView ID="gvSession" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" CssClass="dash-col" OnRowDeleting="gvSession_RowDeleting" DataSourceID="SqlDataSource3">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:BoundField DataField="ProgramID" HeaderText="ProgramID" SortExpression="ProgramID" Visible="False" />

                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditSession.aspx?ID={0}" Text="Edit" />
                        <asp:ButtonField CommandName="Delete" Text="Delete" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM InitialValues WHERE Type='Invitation' AND ParentID IN (SELECT ID FROM Invitations WHERE SessionID=@ID); DELETE FROM InitialValues WHERE Type='Session' AND ParentID=@ID; DELETE FROM Invitations WHERE SessionID=@ID; DELETE FROM Subjects WHERE SessionID=@ID; DELETE FROM Sessions WHERE ID=@ID;" SelectCommand="SELECT * FROM [Sessions] WHERE ([ProgramID] = @ProgramID)">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="gvVariable" Name="ID" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:QueryStringParameter Name="ProgramID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $("a[class='abbtn fancybox']").fancybox();

            $('a[href*="EditVariable.aspx?ID="]').fancybox({ 'type': 'iframe', 'width': '710px' });
            $('a[href*="DuplicateStage.aspx?ID="]').fancybox({ 'type': 'iframe', 'width': '710px' });
            $('a[href*="MoveStage.aspx?ID="]').fancybox({ 'type': 'iframe', 'width': '710px' });

            $('a').filter(function (index) { return $(this).text() === "Delete"; }).click(function () { return confirm('Are you sure you want to delete this item?'); })
        });

    </script>
</asp:Content>
